package course

import (
	"aifuture.cloud/hanlders"
	"aifuture.cloud/services/course"
	"github.com/gin-gonic/gin"
)

type CourseHandler struct {
}

func NewCourseHandler() *CourseHandler {
	return &CourseHandler{}
}

//对外提供服务
func (c *CourseHandler) List(ctx *gin.Context) {
	//课程查询器
	mockQueryInteraptor := course.NewMock()
	courseSvc := course.NewCourSvc(mockQueryInteraptor) //注入课程查询器
	err, courseinfo := courseSvc.List()
	hanlders.HandlerError(err, ctx)
	hanlders.SuccessResponseHandler(ctx, courseinfo)
}

type CourseDetailReq struct {
	CourseId int `query:"course_id" binding:"required"`
}

//kec xiangq
func (c *CourseHandler) Detail(ctx *gin.Context) {
	//课程查询器
	var courseDetailReq CourseDetailReq
	err := ctx.ShouldBind(&courseDetailReq)
	hanlders.HandlerError(err, ctx)
	mockQueryInteraptor := course.NewMock()
	courseSvc := course.NewCourSvc(mockQueryInteraptor) //注入课程查询器
	err, courseinfo := courseSvc.Detail(courseDetailReq.CourseId)
	hanlders.HandlerError(err, ctx)
	hanlders.SuccessResponseHandler(ctx, courseinfo)
}
